<template>
    <view>
		<view class="cu-list menu sm-border card-menu margin-top guoshao-menu" >
			<view class="cu-item guoshao-menu">
				<view class="">
					<view class="guoshao-touxiang-one">
						<image src="../../static/images/user.png" v-if="!isLogin"></image>
						<image :src="user.avatarUrl" v-if="isLogin"></image>
					</view>
					<view class="guoshao-user-name">
						<text class="text-grey" v-if="!isLogin">用户名</text>
						<text class="text-black" v-if="isLogin">{{user.nickName}}</text>
					</view>
				</view>
				<view class="action">
					<button open-type="getUserInfo" class="cu-btn round lines-blue" @click="miniLogin" v-if="!isLogin">
						登录
					</button>
				</view>
			</view>
		</view>
		
		<view class="cu-list menu sm-border card-menu margin-top " v-if="!closeAll">
			<view class="cu-item arrow " open-type="getUserInfo" 
			@click="jumpClickCreator" data-link="/pages/creator/creator" 
			data-tp="creator" v-if="!close_creator">
				<view class="content">
					<text class="cuIcon-discover text-blue"></text>
					<text class="text-black">创作者中心</text>
				</view>
			</view>
			<!-- #ifdef MP-TOUTIAO -->
			<view class="cu-item arrow"  v-if="!close_apply">
				<view class="content" open-type="getUserInfo" @click="jumpClick"  
				data-link="/pages/apply/apply" data-tp="creator">
					<text class="cuIcon-profile text-blue"></text>
					<text class="text-black">创作者申请</text>
				</view>
			</view>
			<!-- #endif -->
		</view>
		
		<view class="cu-list menu sm-border card-menu margin-top" >
			
			<view class="cu-item arrow" >
				<view class="content" open-type="getUserInfo"  @click="handlerPostTrack" data-track="favorites">
					<text class="cuIcon-favor text-blue"></text>
					<text class="text-black">我的收藏</text>
				</view>
			</view>
			
			<view class="cu-item arrow" @click="jumpClick" data-link="/pages/about/problem">
				<view class="content">
					<text class="cuIcon-question text-blue"></text>
					<text class="text-black">常见问题</text>
				</view>
			</view>
			
			<!-- #ifdef MP-TOUTIAO -->
			<view class="cu-item arrow" >
				<view class="content" @click="openAwemeUserProfile" >
					<text class="cuIcon-mark text-blue"></text>
					<text class="text-black">联系我们</text>
				</view>
			</view>
			<view class="cu-item arrow" >
				<button class="cu-btn content" open-type="share" >
					<text class="cuIcon-share text-blue"></text>
					<text class="text-black">分享给朋友</text>
				</button>
			</view>
			<!-- #endif -->
			
			<!-- #ifdef MP-KUAISHOU -->
			<view class="cu-item arrow" >
				<view class="content" @click="copyContact" >
					<text class="cuIcon-mark text-blue"></text>
					<text class="text-black">联系我们</text>
				</view>
			</view>
			<view class="cu-item arrow" >
				<button class="cu-btn content" open-type="share" style="box-shadow: rgba(243, 243, 243, 0.1) 0 0 0 0.5px inset;">
					<text class="cuIcon-share text-blue"></text>
					<text class="text-black">分享给朋友</text>
				</button>
			</view>
			<!-- #endif -->
		
			
			<view class="cu-item arrow" @click="jumpClick" data-link="/pages/setup/setup">
				<view class="content">
					<text class="cuIcon-settings text-blue"></text>
					<text class="text-black">设置</text>
				</view>
			</view>

		</view>

        <!--加载框 start-->
        <tui-loading :visible="loading"></tui-loading>
        <!--加载框 end-->
        
    </view>
</template>

<script>
import tuiLoading from '../../components/loading/loading';
/*
 * Author: 郭少
 * github: https://github.com/guoshao99/wallpaper-applet
 * gitee: https://gitee.com/guoshao99/wallpaper-applet
 * QQ：2549789059
 * 微信：2549789059
 */

const Authentication = require('../../utils/authentication.js');

const util = require('../../utils/util.js');

const http = require('../../utils/http.js');

const Constants = require('../../utils/constants.js');

let setinad;

export default {
    components: {
        tuiLoading
    },
    data() {
        return {
			isSuccess:Authentication.getIsSuccess(),
			user:Authentication.getMiniUser(),
			isLogin:Authentication.isLogin(),
            //是否显示modal
            modelShow: false,
            //modal的高度
            height: {},
            pagead: 5,
            thisPage: 'ucenter',
            integra: 0,

            setAD: {
                banner: '',
                videoid: '',
            },

            loading: false,
			loginReq:false,
			userId:Authentication.getUserId(),
			//admin:'a08f93db1c204fd1986db37dd51914a1'
			admin:'a08f93db1c204fd1986db37dd51914a1',
			close_creator:false,
			close_apply:false,
			closeAll:false,
			configs:[],
        };
    },
    onLoad() {
        let that = this; //配置信息  begin
		util.getConfigs(this,"kuaishou");
    },
    onShow: function (options) {
        let that = this;
        that.setData({
            user: Authentication.getMiniUser(),
			isLogin:Authentication.isLogin(),
			isSuccess:Authentication.getIsSuccess(),
			userId:Authentication.getUserId()
        });
		this.loadCreateConfig();
    },
    onHide() {
        clearInterval(setinad);
    },
    onShareAppMessage: function (option) {
        var that = this;
        uni.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline']
        });
        return {
          title: '高清壁纸，背景图，表情包，头像任您选',
          desc: '高清壁纸，背景图，表情包，头像任您选',
          path: '/pages/index/index', // ?后面的参数会在转发页面打开时传入onLoad方法
          //imageUrl: 'https://e.com/e.png', // 支持本地或远程图片，默认是小程序 icon
          templateId: 'iljxdp5m8obe3n1nf2',
          success () {
        	console.log('转发发布器已调起，并不意味着用户转发成功，微头条不提供这个时机的回调');
          },
          fail () {
        	console.log('转发发布器调起失败');
          }
        }
    },
    //转发朋友圈
    onShareTimeline: function () {
        var that = this;
        return {
            title: that.shares.share_title,
            imageUrl: that.shares.share_image
        };
    },

    methods: {
        miniLogin:function(){
			let that = this;
			if(!that.loginReq){
				that.loginReq = true;
				http.getUserProfile(function(){
					uni.showLoading({
						title:'正在登录'
					})
					setTimeout(function(){
						that.setData({
						    user: Authentication.getMiniUser(),
							isLogin:Authentication.isLogin(),
							userId:Authentication.getUserId()
						});
						uni.hideLoading()
					},1000);
					//that.loginReq = false;
				},that);
			}
		},
		loadCreateConfig:function(){
			let that = this;
			
			var params = {
				url: '/config/loadCreateConfig',
				method: 'get',
				data: {},
				callBack: function (res) {
					console.log(res)
					if (res.code == 200) {
						that.close_creator = res.data.close_creator == '是' ? true : false;
						that.close_apply = res.data.close_apply == '是' ? true : false;
						that.closeAll = res.data.close_all == '是' ? true : false;
					}
				}
			};
			http.request(params);
		},

        handlerPostTrack: function (e) {
			let that = this;
            if (!this.isLogin) {
                that.miniLogin();
                return;
            }

            let track = e.currentTarget.dataset.track;
            uni.navigateTo({
                url: '/pages/list/list?track=' + track
            });
        },

		jumpClickCreator:function(e){
			let that = this;
			if (!this.isLogin) {
				that.miniLogin();
				return;
			}
			let link = e.currentTarget.dataset.link;
			//验证是否创作者
			var params = {
				url: '/u/my/isCreator',
				method: 'get',
				data: {
				},
				callBack: function (res) {
					if (res.code == 200) {
						uni.navigateTo({
							url: link
						});
					}else{
						uni.showToast({
							title: '您不是创作者',
							icon: 'none',
							duration: 2000
						});
					}
				}
			};
			http.request(params);
		},

        jumpClick: function (e) {
			
			let that= this;
			
            let tp = e.currentTarget.dataset.tp;

            if (tp == 'creator') {
                if (!this.isLogin) {
					that.miniLogin();
                    return;
                }
				
            }
			let link = e.currentTarget.dataset.link;
			uni.navigateTo({
				url: link
			});
            
        },

		openAwemeUserProfile:function(){
			tt.openAwemeUserProfile({
			  success: (res) => {
			    console.log(res);
			  },
			});
		},
		copyContact: function (e) {
		    uni.setClipboardData({
		        data: this.configs[0].value,
		        success: function (res) {
		            setTimeout(function(){
						uni.showToast({
						    title: '官方快手号复制成功',
						    duration: 2000,
							icon:'none',
						    success(res) {},
						
						    fail(res) {}
						});
					},500)
		        }
		    });
		},
    }
};
</script>
<style>
@import './ucenter.css';
</style>
